package com.kaigejava.queue.circlearrayqueue;

import com.kaigejava.queue.ArrayQueue;

import java.util.Scanner;

/**
 * @author kaigejava
 * 循环队列测试类
 */
public class CircleArrayQueueDemo {

    public static void main(String[] args) {
        CircleArrayQueue queue = new CircleArrayQueue(4);
        //用户输入数据
        char key = ' ';
        Scanner sc = new Scanner(System.in);
        boolean loopFlag = true;
        while(loopFlag){
            System.out.println("s(show)：显示队列");
            System.out.println("e(exit)：退出程序");
            System.out.println("a(addQueue)：添加数据到队列");
            System.out.println("g(get)：从队列中获取数据");
            System.out.println("h(head)：偷偷查看下队列头的数据");
            key = sc.next().charAt(0);
            switch (key){
                case 's':
                    try {
                        queue.showAll();
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'a':
                    System.out.println("请输入一个数:");
                    int val = sc.nextInt();
                    queue.addQueue(val);
                    break;
                case 'g':
                    try {
                        int res = queue.getQueue();
                        System.out.printf("从队列中获取到的数据为:%d \n ",res);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try {
                        int res = queue.hearQueue();
                        System.out.printf("队列头数据为:%d \n ",res);
                    }catch (Exception e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    sc.close();
                    loopFlag = false;
                    break;
                default:
                    break;

            }

        }
        System.out.println("程序已经退出了~~~");
    }
}
